package com.turing.post.cardmanagement.util;

import java.io.Serializable;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.HashMap;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

/**
 * 已制未售卡库存
 * 
 * @author ys
 * @date 2012-12-17
 */
@SuppressWarnings("serial")
@Entity
@Table(name = "CardStock")
public class CardStock implements Serializable {

	public CardStock() {
		super();
	}

	/**
	 * 制卡批次号
	 */
	private String BatchNo;
	/**
	 * 卡顺序号
	 */
	private String CardSeqNo;
	/**
	 * 卡号
	 */
	private String CardNo;
	/**
	 * 卡密文密码
	 */
	private String CardPwd;
	/**
	 * 二磁道内容
	 */
	private String TwoTrackContent;
	/**
	 * 三磁道内容
	 */
	private String ThirdTrackContent;
	/**
	 * 所属发卡商机构
	 */
	private String IssueBranchNo;
	/**
	 * 所属销售机构
	 */
	private String SaleBranchNo;
	/**
	 * 状态
	 */
	private String Status;

	private BigInteger salesGetCardOrderId;

	/**
	 * 正常
	 */
	public final static String CARDSTOCK_STATUS_NORMAL = "0";

	/**
	 * 在途
	 */
	public final static String CARDSTOCK_STATUS_INTRANSIT = "1";

	/**
	 * 已销售
	 */
	public final static String CARDSTOCK_STATUS_SALED = "2";

	/**
	 * 已销售出库等待激活
	 */
	public final static String CARDSTOCK_STATUS_WAITACTIVATE = "3";

	/**
	 * 取消激活待重新入库
	 */
	public final static String CARDSTOCK_STATUS_ACTIVATECANCEL = "4";

	/**
	 * 已重新入库待取消销售
	 */
	public final static String CARDSTOCK_STATUS_WAITSALECANCEL = "5";

	/**
	 * 丢失、损坏、不再制卡等
	 */
	public final static String CARDSTOCK_STATUS_MISSING = "9";

	@Column(name = "BATCHNO", nullable = false)
	public String getBatchNo() {
		return BatchNo;
	}

	public void setBatchNo(String batchNo) {
		BatchNo = batchNo;
	}

	@Id
	@Column(name = "CARDSEQNO", nullable = false)
	public String getCardSeqNo() {
		return CardSeqNo;
	}

	public void setCardSeqNo(String cardSeqNo) {
		CardSeqNo = cardSeqNo;
	}

	@Column(name = "CARDNO", nullable = false)
	public String getCardNo() {
		return CardNo;
	}

	public void setCardNo(String cardNo) {
		CardNo = cardNo;
	}

	@Column(name = "CARDPWD", nullable = false)
	public String getCardPwd() {
		return CardPwd;
	}

	public void setCardPwd(String cardPwd) {
		CardPwd = cardPwd;
	}

	@Column(name = "TWOTRACKCONTENT", nullable = false)
	public String getTwoTrackContent() {
		return TwoTrackContent;
	}

	public void setTwoTrackContent(String twoTrackContent) {
		TwoTrackContent = twoTrackContent;
	}

	@Column(name = "THIRDTRACKCONTENT", nullable = false)
	public String getThirdTrackContent() {
		return ThirdTrackContent;
	}

	public void setThirdTrackContent(String thirdTrackContent) {
		ThirdTrackContent = thirdTrackContent;
	}

	@Column(name = "ISSUEBRANCHNO", nullable = true)
	public String getIssueBranchNo() {
		return IssueBranchNo;
	}

	public void setIssueBranchNo(String issueBranchNo) {
		IssueBranchNo = issueBranchNo;
	}

	@Column(name = "SALEBRANCHNO", nullable = true)
	public String getSaleBranchNo() {
		return SaleBranchNo;
	}

	public void setSaleBranchNo(String saleBranchNo) {
		SaleBranchNo = saleBranchNo;
	}

	@Column(name = "STATUS", nullable = true)
	public String getStatus() {
		return Status;
	}

	public void setStatus(String status) {
		Status = status;
	}

	@Column(name = "SalesGetCardOrderId")
	public BigInteger getSalesGetCardOrderId() {
		return salesGetCardOrderId;
	}

	public void setSalesGetCardOrderId(BigInteger salesGetCardOrderId) {
		this.salesGetCardOrderId = salesGetCardOrderId;
	}

	public static String getErrorStatus(HashMap<String, Integer> map) {
		Object[] key = map.keySet().toArray();
		Arrays.sort(key);
		String res = "";
		for (Object obj : key) {
			res += getStatusDesc(obj.toString()) + map.get(obj.toString())
					+ "张,";
		}
		return res.substring(0, res.length() - 1);
	}

	private static String getStatusDesc(String str) {
		if (CARDSTOCK_STATUS_NORMAL.equals(str)) {
			return "正常";
		} else if (CARDSTOCK_STATUS_INTRANSIT.equals(str)) {
			return "在途";
		} else if (CARDSTOCK_STATUS_SALED.equals(str)) {
			return "已销售";
		} else if (CARDSTOCK_STATUS_WAITACTIVATE.equals(str)) {
			return "已销售出库等待激活";
		} else if (CARDSTOCK_STATUS_ACTIVATECANCEL.equals(str)) {
			return "取消激活待重新入库";
		} else if (CARDSTOCK_STATUS_WAITSALECANCEL.equals(str)) {
			return "已重新入库待取消销售";
		} else if (CARDSTOCK_STATUS_MISSING.equals(str)) {
			return "丢失损坏";
		}
		return "";
	}
}
